package edu.pku.sei.transformation.editor.actions;

import java.io.File;

import org.eclipse.jface.action.Action;
import org.eclipse.ui.PartInitException;

import edu.pku.sei.transformation.editor.views.editor.TextEditor;
import edu.pku.sei.transformation.editor.views.icons.IconsProvider;

public class ViewFileAction extends Action {
	private File file = null;
	public ViewFileAction(String path) {
		this.file = new File(path);
		this.setText("View File");
		this.setImageDescriptor(IconsProvider.getImageDescriptor(IconsProvider.FILE_ICO));
	}
	
	@Override
	public boolean isEnabled() {
		if (file != null && file.exists())
			return true;
		else
			return false;
	}
	
	@Override
	public void run() {
		try {
			TextEditor.openInDefaultTextEditor(file.getAbsolutePath());
		} catch (PartInitException e) {
			e.printStackTrace();
		}
	}
}
